/*
 * @Author: your name
 * @Date: 2021-05-18 22:24:04
 * @LastEditTime: 2021-05-18 23:15:57
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \learn_type\src\main.rs
 */
 #[derive(Debug)]
 struct Matrix(f32, f32, f32, f32);
 struct Point{
     x:f32,
     y:f32,
 }

 #[allow(dead_code)]
 struct Rectangle{
     p1:Point,
     p2:Point,
 }

 // 交换元组数据方向
fn reverse(pair:(i32, bool)) -> (bool, i32){
    let (intger, boolean) = pair;

    (boolean, intger)
}

// array[T;size]
// slice &[T]
use std::mem;

fn analyse_slice(slice:&[i32]){
    println!("first element of the slice is :{}", slice[0]);
    println!("the slice has {} element", slice.len());
}
fn main() {
    let the = (32, false);
    let pairs:(bool, i32) = reverse(the);

    let matrix = Matrix(2.0, 22.0, 21.5, 15.2);
    println!("matrix is {:#?}", matrix);
    println!("pairs bool is {} , intger is {}", pairs.0, pairs.1);
    println!("pairs is {:?}", pairs);
    
    // 定义数组
    let xs = [1,2,3,4,5];
    let ys:[i32; 500] = [0;500];
    println!("array size is {}", xs.len());
    // 数组在栈中分配
    println!("arrya occupies {} bytes", mem::size_of_val(&xs));

    // 数组可以自动被借用成为slice
    println!("borrow the whole array as a slice");
    analyse_slice(&xs);
    println!("borrow a section array as a slice");
    analyse_slice(&ys[1 .. 4]);

    let point = Point{x:0.3, y:0.4};

    println!("point coordinates ({} {})", point.x, point.y);
    let new_point = Point{x:0.5, ..point};
    println!("new_point coordinates ({} {})", new_point.x, new_point.y);

    let _rectangle = Rectangle{
        p1: point,
        p2: new_point,
    };
    println!("_rectangle region {}", _rectangle.p1.x);

    let x = 10;
    let z = {
        2*x;
    };
    println!("z is {:?}",z);
}
